package com.gdwProject.tankgame4;

/**
 * @author 关道伟
 * @version 1.0
 */
public class Shot implements Runnable {
    int x;//子弹x坐标
    int y;//y坐标
    int direct ;//方向
    int speed = 2;//速度
    boolean isLive = true;

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public Shot(int x, int y, int direct) {
        this.x = x;
        this.y = y;
        this.direct = direct;
    }

    @Override
    public void run() {//射击行为
        while (true) {
            try {
                Thread.sleep(20);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            //根据方向改变坐标
            switch (direct) {
                case 0:
                    y -= speed;
                    break;
                case 1:
                    x += speed;
                    break;
                case 2:
                    y += speed;
                    break;
                case 3:
                    x -= speed;
                    break;
            }

            //test
            System.out.println("子弹x=" + x + ", y=" + y);
            if (!(x >= 0 && x <= 1000 && y >= 0 && y <= 750)) {
                System.out.println("子弹出界销毁...");
                isLive = false;
                break;
            }


        }
    }
}
